package com.local.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author relieved-gao
 * @version 1.0 , 2017/11/9
 * @since 1.0
 */
public class TestMain {
    public static void main(String[] args) {
        Round round = new Round();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 1; j <= 50; j++) {
                    round.subMethod(j);
                }
            }
        }).start();
        for (int l = 1; l <= 50; l++) {
            round.mainMethod(l);
        }
    }

}

class Round {
    private static boolean isSubShould = true;

    public synchronized void subMethod(int outer) {
        while (!isSubShould) {
            try {
                //自己阻塞
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        for (int j = 1; j <= 10; j++) {
            System.out.println("chirld  outer ========" + outer + "chirld round =============" + j);
        }
        //唤醒主线程
        isSubShould = false;
        this.notify();

    }

    public synchronized void mainMethod(int outer) {
        while (isSubShould) {
            try {
                //自己阻塞
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        for (int k = 1; k <= 100; k++) {
            System.out.println("main  outer ========" + outer + "main round =============" + k);
        }
        //唤醒子线程
        isSubShould = true;
        this.notify();
    }
}